﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_QLSV.BusinessClassLibrary
{
    public class HocKyBUS
    {
        private static QLSVDataContext db = new QLSVDataContext();
        public static bool ThemHocKy(HocKy HocKy)
        {
            try
            {
                db.HocKies.InsertOnSubmit(HocKy);
                db.SubmitChanges();
            }
            catch
            {
                //conflict primary key - the item is exist
                return false;
            }
            return true;
        }
        public static bool XoaHocKy(int idHK)
        {
            try
            {
                HocKy old = db.HocKies.Single(kh => kh.mahocky == idHK);
                db.HocKies.DeleteOnSubmit(old);
                db.SubmitChanges();
            }
            catch
            {
                // the item is not exist
                return false;
            }
            return true;
        }
        public static bool CapNhatKhoaHoc(int id, HocKy hk)
        {
            try
            {
                HocKy old = db.HocKies.Single(kh => kh.mahocky == id);
                old.tenhocky = hk.tenhocky;
                db.SubmitChanges();
            }
            catch
            {
                // the item is not exist
                return false;
            }
            return true;
        }
        public static List<HocKy> LayDanhSach()
        {
            return db.HocKies.ToList();
        }
    }
}
